<!--
* @description 诛仙摆摊注册
* @fileName register.vue
* @author huangyu
* @date 2023/02/14 14:09:42
!-->
<template>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px">
        <el-form-item label="账号/摆摊号" prop="gameCode">
            <el-input v-model="ruleForm.gameCode" placeholder="请输入账号"></el-input>
            <div class="color_warning">没有摆摊号，请联系QQ：834442545</div>
        </el-form-item>
        <el-form-item label="密码" prop="password">
            <el-input v-model="ruleForm.password" show-password placeholder="请输入密码"></el-input>
        </el-form-item>
        <!-- <el-form-item label="QQ号" prop="qq">
            <el-input v-model="ruleForm.qq" placeholder="请输入QQ号"></el-input>
        </el-form-item>
        <el-form-item label="游戏名称" prop="gameName">
            <el-input v-model="ruleForm.gameName" placeholder="请输入游戏名称"></el-input>
        </el-form-item> -->
        <el-form-item>
            <el-button type="primary" @click="registerForm('ruleForm')">注册</el-button>
        </el-form-item>
    </el-form>
</template>

<script>
import { get } from '@/common/app.js'
import md5 from 'js-md5';
import { zxGameIds } from "@/enum/zhuxian.js"
export default {
    components: {},
    data() {
        return {
            ruleForm: {
                gameCode: "",
                gameName: "",
                qq: "",
                isSecrecy: false,
                gameId: zxGameIds[0].id, //默认传入 zxGameId: 1，东方诛仙
                password: "", //默认密码123456, 东方诛仙不需要密码
            },

            rules: {
                gameCode: [{ required: true, message: '请输入账号', trigger: 'blur' },],
                gameName: [{ required: true, message: '请输入游戏名称', trigger: 'blur' },],
                qq: [{ required: true, message: '请输入QQ号', trigger: 'blur' },],
                password: [{ required: true, message: '请输入密码', trigger: 'blur' },],
            },
        }
    },
    mounted() {

    },
    methods: {
        registerForm(formName){
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    this.register()
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },
        register(){
            this.ruleForm.password = md5(this.ruleForm.password)
            let params = {
                type: 'getLogin',
                api: 'api-register',
                data: this.ruleForm,
            }
            get('game', params).then(res => {
                if (res) {
                    console.log(res)
                    if(res.type=='error'){
                        this.$message.error(res.msg)
                        return
                    }
                    if(res.id){
                        this.$message.success("注册成功！") 
                    }
                }
            })
        },
    },
}
</script>

<style scoped>

</style>